/*
 * Copyright (2025) UCT Ltd. and/or its affiliates
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { BigIntToStringConvertor, Columns, ColumnType, Embedded, Entity, RdbDao, RdbDatabase } from 'rdbstore';
import { SearchParams, DeleteParams } from '../../../types/types'
import { Env } from '../../../env/Env'
import { getDB } from '../../../utils/RdbUtil'
  //#region Human-Code Preservation

  //#endregion Human-Code Preservation
const apiURL: string = Env.CLOUD_API_URL
let _table_name_Dao: RdbDao<_table_name_>;

@Entity({
  tableName: '_table_name_',
  index: [{ name: 'idIndex', columnName: ['id'], unique: true }]
})
export class _table_name_ {
  REPLACE_MODELFIELDS

  toString(): string {
    return `REPLACE_MODELTOSTRING`;
  }

  static async get_TableName_List(page: number, pageSize: number, searchParams?: Record<string, string | number | boolean>){
    let db: RdbDatabase  = getDB('uctoo.db');
    return db.extension.axiosPlugin?.setDao(_table_name_Dao).api().get(`/_table_name_/${pageSize}/${page}`, {
      params: searchParams,
      headers: { 
        'Content-Type': 'application/json;charset=utf-8',
        'Authorization': `Bearer ${AppStorage.get<string>('access_token')}`
      },
      baseURL: apiURL,
      dataKey: '_tableName_s'
    })
  }
  static async  get_TableName_(id: string){
    let db: RdbDatabase  = getDB('uctoo.db');
    return db.extension.axiosPlugin?.setDao(_table_name_Dao).api().get(`/_table_name_/${id}`, {
      headers: { 
        'Content-Type': 'application/json;charset=utf-8',
        'Authorization': `Bearer ${AppStorage.get<string>('access_token')}`
      },
      baseURL: apiURL,
    })
  }
  static async  add_TableName_(data: Partial<_table_name_>){
    let db: RdbDatabase  = getDB('uctoo.db');
    return db.extension.axiosPlugin?.setDao(_table_name_Dao).api().post('/_table_name_/add', data, {
      headers: { 
        'Content-Type': 'application/json;charset=utf-8',
        'Authorization': `Bearer ${AppStorage.get<string>('access_token')}`
      },
      baseURL: apiURL,
    })
  }
  static async  edit_TableName_(data: edit_TableName_Params){
    let db: RdbDatabase  = getDB('uctoo.db');
    return db.extension.axiosPlugin?.setDao(_table_name_Dao).api().post('/_table_name_/edit', data, {
      headers: { 
        'Content-Type': 'application/json;charset=utf-8',
        'Authorization': `Bearer ${AppStorage.get<string>('access_token')}`
      },
      baseURL: apiURL,
    })
  }
  static async  delete_TableName_(data: DeleteParams){
    let db: RdbDatabase  = getDB('uctoo.db');
    return db.extension.axiosPlugin?.setDao(_table_name_Dao).api().post('/_table_name_/del', data, {
      headers: { 
        'Content-Type': 'application/json;charset=utf-8',
        'Authorization': `Bearer ${AppStorage.get<string>('access_token')}`
      },
      baseURL: apiURL,
    })
  }

  //#region Human-Code Preservation

  //#endregion Human-Code Preservation
}

interface edit_TableName_Params {
  REPLACE_MODELEDITPARAMS
}
  //#region Human-Code Preservation

  //#endregion Human-Code Preservation